package org.example.flinksql.test.custom;


import org.apache.flink.table.annotation.DataTypeHint;
import org.apache.flink.table.functions.ScalarFunction;
import org.example.util.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.math.BigDecimal;


public class TransTotalCapiFunc extends ScalarFunction { ;
    private final Logger logger = LoggerFactory.getLogger(TransTotalCapiFunc.class);

    @DataTypeHint("DECIMAL(20, 6)")
    public BigDecimal eval(String str) {
        try {
            Double aDouble = Utils.getDoubleFromStr(str);
            return BigDecimal.valueOf(aDouble);
        } catch (Exception e) {
            logger.warn(String.format("%s :: %s :: [%s]", e.getMessage(), e.getCause(), str));
            return null;
        }
    }
}
